'use strict';

var a = function(){
	String.prototype.trim=function(){
		return this.replace(/(^\s*)|(\s*$)/g, '');
	};
	String.prototype.ltrim=function(){
		return this.replace(/(^\s*)/g,'');
	};
	String.prototype.rtrim=function(){
		return this.replace(/(\s*$)/g,'');
	};
	
	var JM = {
	version: ".1",
	name: "JM",
	author: "麦草CMS"
	};
	window.JM = JM;
	
	var arr = JM.array = {
		each: function(){}
	};
	//var z;
	var getType = JM.getType = function(vari){
		var s = Object.prototype.toString.call(vari).toLowerCase().match(/\[object (.*)\]/);
		return s[1];
	};
	
	//alert(getType(z));
	
	var browser = JM.browser={};
	var os = JM.os = {};
	(function(){
  		var _ua = navigator.userAgent.toLowerCase();
  		var s;
  		(s = _ua.match(/rv:([\d\.]+)\) like gecko/)) ? JM.browser.ie = s[1] :
  		(s = _ua.match(/msie ([\d\.]+)/)) ? JM.browser.ie = s[1] :
  		(s = _ua.match(/edge\/([\d\.]+)/)) ? JM.browser.edge = s[1] :
  		(s = _ua.match(/firefox\/([\d\.]+)/)) ? JM.browser.firefox = s[1] :
  		(s = _ua.match(/(?:opera|opr).([\d\.]+)/)) ? JM.browser.opera = s[1] :
  		(s = _ua.match(/chrome\/([\d\.]+)/)) ? JM.browser.chrome = s[1] :
  		(s = _ua.match(/version\/([\d\.]+).*safari/)) ? JM.browser.safari = s[1] : JM.browser.other = "Other";
  		if(JM.browser.ie){ JM.browser.info = 'IE: ' + JM.browser.ie;}
  		if(JM.browser.edge){ JM.browser.info = 'EDGE: ' + JM.browser.edge;}
  		if(JM.browser.firefox){ JM.browser.info = 'Firefox: ' + JM.browser.firefox;}
  		if(JM.browser.chrome){ JM.browser.info = 'Chrome: ' + JM.browser.chrome;}
  		if(JM.browser.opera){ JM.browser.info = 'Opera: ' + JM.browser.opera;}
  		if(JM.browser.safari){ JM.browser.info = 'Safari: ' + JM.browser.safari;}
		if(JM.browser.other){ JM.browser.info = JM.browser.other;}
	})();
	//alert(browser.info);
	
	(function(){
  		var _ua = navigator.userAgent.toLowerCase();
  		var s;
  		(s = _ua.match(/windows nt ([\d\.]+)/)) ? JM.os.win = s[1] :
  		(s = _ua.match(/mac os x ([\d_]+)/)) ? JM.os.mac = s[1] :
  		(s = _ua.match(/iphone os ([\d_]+)/)) ? JM.os.ios = s[1] :
  		(s = _ua.match(/ipad;.+cpu os ([\d_]+)/)) ? JM.os.ipad = s[1] :
  		(s = _ua.match(/android ([\d\.]+)/)) ? JM.os.android = s[1] :
  		(s = _ua.match(/linux.+[^android]/)) ? JM.os.linux = "" : JM.os.other = "Other";
  		if(JM.os.win){ JM.os.info = 'Win : ' + JM.os.win;}
  		if(JM.os.mac){ JM.os.info = 'Mac os: ' + JM.os.mac;}
  		if(JM.os.ios){
			JM.os.info = 'IOS: ' + JM.os.ios;
			JM.os.isMobile = true;
		}
  		if(JM.os.ipad){ JM.os.info = 'IOS: ' + JM.os.ipad + " for Ipad";}
  		if(JM.os.android){
			JM.os.info = 'Android: ' + JM.os.android;
			JM.os.isMobile = true;
		}
  		if(JM.os.linux){ JM.os.info = 'Linux: ' + JM.os.linux;}
		if(JM.os.other){ JM.os.info = JM.os.other;}
	})();
	//alert(os.info)
	
	var utils = JM.utils ={
		name: "JMUtils",
		version: ".1",
		author: "麦草CMS",
		getViewport: function(){
			if (document.compatMode == "BackCompat"){
				return {
					width: document.body.clientWidth,
					height: document.body.clientHeight
				};
			} else {
				return {
					width: document.documentElement.clientWidth,
					height: document.documentElement.clientHeight
				};
			}
		},
		getPagearea: function(){
			if (document.compatMode == "BackCompat"){
				return {
					width: Math.max(document.body.scrollWidth,document.body.clientWidth),
					height: Math.max(document.body.scrollHeight,document.body.clientHeight)
				};
			} else {
				return {
					width: Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth),
					height: Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)
				};
			}
		},
		getScroll: function(){
			return {
				left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
				top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
			};
		},
		/*getRel: function(elem){
			var absPos = this.getAbs(elem),
				scroll = this.getScroll();
			return {
				x: absPos.x - scroll.left,
				y: absPos.y - scroll.top
			};
		},
		//递归法取得的元素绝对位置有误差，offsetTop获得的是相对位置的四舍五入值，
		getAbs: function(elem){
			var x = 0, y = 0;
			while (elem !== null){
				alert(elem.nodeName)
				x += (elem.offsetLeft);// + elem.clientLeft);
				y += (elem.offsetTop);// + elem.clientTop);
				elem = elem.offsetParent;
			}
			return {
				x: x,
				y: y
			};
		},*/
		getRel: function(elem){
			var domRect = elem.getBoundingClientRect();
			//alert(document.body.offsetTop)
			return {
				x: domRect.left,
				y: domRect.top
			};
		},
		getAbs: function(elem){
			var relPos = this.getRel(elem),
				scroll = this.getScroll();
			return {
				x: relPos.x + scroll.left,
				y: relPos.y + scroll.top
			};
		},
		setCookie: function(name, value, options){
			var theCookie, now, expires;
			if(name && value){
				theCookie = name + "=" + encodeURIComponent(value);
			}else{
				return;
			}
			if(options && getType(options) == "object"){
				if(options.expires){
					now = new Date();
					expires =  now.getTime() + (options.expires * 1000);
					now.setTime(expires);
					theCookie += "; expires=" + now.toGMTString();
				}
				if(options.path){ theCookie += "; path=" + options.path;}
				if(options.domain){ theCookie += "; domain=" + options.domain;}
			}
			document.cookie = theCookie;
		},
		getCookie: function(name){
			var cookies = document.cookie,
				arr = cookies.split(";"),
				arr1;
			for(var i = 0; i < arr.length; i++){
				arr1 = arr[i].split("=");
				if(arr1[0] === name){ return decodeURIComponent( arr1[1] );}
			}
			return null;
			
		}
	};
	
	var error = JM.error = {
		name: "JMError",
		version: ".1",
		make: function(module, description){
			
		}
	};

	//事件
	var evt1 = JM.event = {
		name : "JMEvent",
		version: ".1",
		author: "麦草CMS",
		addEvent : function(elem, evtType, handler, bool){
			var bool = ("undefined" === typeof bool) ? false: bool;
			if(elem.addEventListener){
				elem.addEventListener(evtType, handler, bool);
			}else if(elem.attachEvent){
				//alert(handler)
				elem.attachEvent("on" + evtType, handler);
			}
		},
		cancelBubble: function(evt){
			if(evt.cancelBubble){
				evt.cancelBubble = true;
			}else if(evt.stopPropagation){
				evt.stopPropagation();
			}
		},
		removeEvent: function(elem, evtType, handler, bool){
			var bool = ("undefined" === bool) ? false: bool;
			if(elem.removeEventListener){
				elem.removeEventListener(evtType, handler, bool);
			}else if(elem.detachEvent){
				elem.detachEvent("on" + evtType, handler);
			}
		},
		getEvent: function(evt){
			var evt = (evt && evt.target) ? evt : ((window.event) ? window.event : null);
			return evt;
		},
		getElement : function(evt){
			return (evt.srcElement) ? evt.srcElement : ((evt.target) ? evt.target : null);
		},
		preventDef: function(evt){
			if(evt.preventDefault){
				evt.preventDefault();
			}else if(evt.returnValue){
				evt.returnValue = false;
			}
		},
		fireEvent: function(elem, evtType, evt){
			if(elem.dispatchEvent(evt)){
				elem.dispatchEvent(evt);
			}else{
				elem.fireEvent(evtType, evt);
			}
		},
		createEvent: function(eventType){
			var evt;
			if(document.createEvent){
				evt = document.createEvent(eventType);
				evt.initEvent("click", true, false);
			}else if(document.createEventObject){
				evt = document.createEventObject();
			}
			return evt;
		}
	};

	//Ajax
	var ajax = JM.ajax = {
		name: "JMAjax",
		version: ".1",
		author: "麦草CMS",
		createXHR: function(){
			var xhr = null;
			if(window.XMLHttpRequest){
 				xhr = new XMLHttpRequest();
			}else if(window.ActivexObject){
    			xhr = new ActivexObject("Microsoft.XMLHTTP");
			}else{
				JM.error.make(this, "创建XMLHttpRequest失败！");
			}
			return xhr;
		},
		make: function(url, options){
			var xhr = this.createXHR();
			var options = options || {};
			var mimeType = null;
			options = {
				async: "undefined" == typeof options.async ? true : options.async,
				//afterSend: options.afterSend || null,
				beforeSend: options.beforeSend || null,
				complete: options.complete || null,
				contentType: options.contentType || "application/x-www-form-urlencoded",
				crossDomain: options.crossDomain || false,
				data: options.data || null,
				dateType: options.dateType || "text",
				error: options.error || null,
				method: options.method || "GET",
				password: options.password || null,
				timeout: parseInt(options.timeout) || 0,
				//status: options.status,
				success: options.success || null,
				username: options.username || null
			};
			if(options.crossDomain && !xhr.withCredentials){
				xhr = new XDomainRequest();
			}
			xhr.onreadystatechange = function(){
				if(xhr.readyState === 4 && xhr.status === 200){
					var response;
					switch(options.dateType){
						case "arrayBuffer":
							if(xhr.responseType){
								response = xhr.response;
							}else{
								response = xhr.responseText;
    							for (var i = 0, len = response.length; i < len; ++i) {
      								var c = response.charCodeAt(i);
      								//String.fromCharCode(c & 0xff);
      								var byte = c & 0xff; 
    							}
							}
							break;
						case "blob":
							if(xhr.responseType){
								response = xhr.response;
							}else{
								response = xhr.responseText;
    							for (var i = 0, len = response.length; i < len; ++i) {
      								var c = response.charCodeAt(i);
      								//String.fromCharCode(c & 0xff);
      								var byte = c & 0xff; 
    							}
							}
							break;
						case "html":
							response = JM.ajax.html(xhr.responseText);
							break;
						case "json":
							if(xhr.responseType){
								response = xhr.response;
							}else{
								response = JM.ajax.makeJSON(xhr.responseText);
							}
							break;
						case "text":
							response = xhr.responseText;
							break;
						case "xml":
							if(xhr.responseType){
								response = xhr.response;
							}else{
								response = xhr.responseXML;
							}
							break;
					}
					if(options.success){ options.success(response, xhr);}
				}else{
				}
			};
			switch(options.dateType){
				case "arrayBuffer":
					if(xhr.responseType){
						xhr.responseType = "arrayBuffer";
					}else{
						mimeType = "text/plain; charset=x-user-defined";
					}
					break;
				case "blob":
					if(xhr.responseType){
						xhr.responseType = "blob";
					}else{
						mimeType = "text/plain; charset=x-user-defined";
					}
					break;
				case "json":
					if(xhr.responseType){
						xhr.responseType = "json";
					}
					break;
				case "xml":
					if(xhr.responseType){
						xhr.responseType = "document";
					}
					break;
				default:
					break;
			}
			if(xhr.timeout){
				xhr.timeout = options.timeout;
			}else{
				//alert(xhr.abort())
				//var timer = setTimeout(xhr.abort(), options.timeout);
			}
			//alert(options.method+url)
 			xhr.open(options.method, url);
			if(xhr.withCredentials){ xhr.withCredentials = options.crossDomain;}
 			xhr.setRequestHeader("Content-Type", options.contentType);
			if(mimeType){
				xhr.overrideMimeType(mimeType);
			}
			if(options.error){ xhr.onerror = options.error;}
			//if(options.timeout){ xhr.ontimeout = options.timeout;}
			if(options.beforeSend){ options.beforeSend(xhr);}
			xhr.send(options.data);
			if(options.complete){ options.complete(xhr);}
		},
		html: function(text, elem){
			var elem = elem, newElem, elems;
			if(elem && elem.nodeType == 1){
				newElem = document.createElement(elem.nodeName);
				for(var i = 0, attrs = elem.attributes; i < attrs.length; i++){
					if(attrs[i].specified){ newElem.setAttribute(attrs[i].name, attrs[i].value);}
				}
				elem.innerHTML = text;
				return elem.parentNode.replaceChild(loop(newElem,elem), elem);
			}else{
				elem = document.createElement("div");
				newElem = document.createElement("div");
				elem.innerHTML = text;
				newElem = loop(newElem, elem);
				elems = newElem.childNodes;
				elem = null;
				newElem = null;
				return elems;
			}
			function loop(newElem, elem){
				for(var i = 0, children = elem.childNodes; i < children.length; i++){
					switch(children[i].nodeType){
						case 1:
							var e = document.createElement(children[i].nodeName);
							for(var j = 0, attrs = children[i].attributes; j < attrs.length; j++){
								if(attrs[j].specified){ e.setAttribute(attrs[j].nodeName, attrs[j].nodeValue);}
							}
							loop(e, children[i]);
							newElem.appendChild(e);
							break;
						case 3:
							var text = document.createTextNode(children[i].nodeValue);
							newElem.appendChild(text);
							break;
						case 8:
							newElem.appendChild(children[i]);
							break;
						case 10:
							newElem.appendChild(children[i]);
							break;
						case 11:
							var e = document.createElement(children[i].nodeName);
							for(var j = 0, attrs = children[i].attributes; j < attrs.length; j++){
								if(attrs[j].specified){ e.setAttribute(attrs[j].nodeName, attrs[j].nodeValue);}
							}
							loop(e, children[i]);
							newElem.appendChild(e);
							break;
					}
				}
				return newElem;
			};
		},
		makeJSON: function(text){
			eval('var json = ' + text);
			return json;
		},
		formSerialize: function(form){
			var parts = [], field = null;
			if(window.FormData){ return new FormData(form);}
			for(var i = 0, len = form.elements.length; i < len; i++){
				field = form.elements[i];
				switch(field.type){
					case "select-one":
						for(var j = 0, oLen = field.options.length; j < oLen; j++){
							var option = field.options[j];
							if(option.selected){
								var oValue;
								if(option.hasAttribute){
									oValue = option.hasAttribute("value") ? option.value : option.text;
								}else{
									oValue = option.Attributes["value"].specified ? option.value : option.text;
								}
								parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(oValue));
								break;
							}
						}
					case "select-multiple":
						for(var j = 0, oLen = field.options.length; j < oLen; j++){
							var option = field.options[j];
							if(option.selected){
								var oValue;
								if(option.hasAttribute){
									oValue = option.hasAttribute("value") ? option.value : option.text;
								}else{
									oValue = option.Attributes["value"].specified ? option.value : option.text;
								}
								parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(oValue));
							}
						}
						break;
					case "radio":
						if(!field.checked){ break;}
					case "checkbox":
						if(!field.checked){ break;}
					case "button":
						break;
					case "reset":
						break;
					case "image":
						break;
					case "submit":
						break;
					case "file":
						break;
					case undefined:
						break;
					default:
						parts.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value));
				}
			}
			return parts.join("&");
				options.beforeSend = function(xhr){
					xhr.setRequestHeader("X-PJAX", true);
					if(options.beforeSend){ options.beforeSend(xhr);}
				};
				options.success = function(response, xhr){
					if(options.success){ options.success(data, xhr);}
					if(JM.pjax.state && JM.pjax.state.title){
						title = JM.pjax.state.title;
					}else{
						if(elem && elem.title){
							title = elem.title;
						}else{
							title = document.title;
						}
					}
					state = {id: id};
					history.pushState(state, title, options.url);
					document.title = title;
					localStorage.setItem(id, response);
				};
		}
	};
	
	//pjax
	var pjax = JM.pjax = {
		name: "JMPjax",
		version: ".1",
		author: "麦草CMS",
		event: null,
		state: null,
		flag: false,
		set: function(name, value){
			this[name] = value;
		},
		make: function(selector, context, options){
			var results = [];
				/*options = options || {};
				options = {
					url: options.url,
					self: options.self,
					eventType: options.eventType || "click",
					async: "undefined" == typeof options.async ? true : options.async,
					beforeSend: options.beforeSend || null,
					complete: options.complete || null,
					contentType: options.contentType || "application/x-www-form-urlencoded",
					crossDomain: options.crossDomain || false,
					data: options.data || null,
					dateType: options.dateType || "text",
					error: options.error || null,
					method: options.method || "GET",
					password: options.password || null,
					timeout: parseInt(options.timeout) || 0,
				//status: options.status,
					success: options.success || null,
					username: options.username || null
				};*/
			if(window.history && window.history.pushState && window.history.replaceState && document.querySelectorAll && window.localStorage){
				if(context){
					if(options.self){
						results.push(context);
					}else if(selector){
						results = context.querySelectorAll(selector);
					}
				}else{
					if(selector){ results = document.querySelectorAll(selector);}
				}
				if(results.length == 0){
					handler(null, options);
					return;
				}
				for(var i = 0; i < results.length; i++){
					JM.event.addEvent(results[i], options.eventType, function(evt){
						var evt = JM.event.getEvent(evt);
						JM.event.preventDef(evt);
						var elem = JM.event.getElement(evt);
						switch(elem.nodeName.toLowerCase()){
							case "a":
								options.url = elem.href;//.replace(/#.*/, "");
								break;
							case "form":
								options.url = elem.action;
								break;
							default:
								if(!options.url){ JM.error.make(JM.pjax, "请设置URL。如handler({url: \"http://www.a.com\"})");}
								break;
						}
						handler(elem, options);
					});
				}
			}
			function handler(elem, options){
				var id = "PJAX-" + (new Date() * 1),
					title,
					opts = options || {},
					state;
				opts = {
					url: options.url,
					self: options.self,
					eventType: options.eventType || "click",
					async: "undefined" == typeof options.async ? true : options.async,
					beforeSend: options.beforeSend || null,
					complete: options.complete || null,
					contentType: options.contentType || "application/x-www-form-urlencoded",
					crossDomain: options.crossDomain || false,
					data: options.data || null,
					dateType: options.dateType || "text",
					error: options.error || null,
					method: options.method || "GET",
					password: options.password || null,
					timeout: parseInt(options.timeout) || 0,
				//status: options.status,
					success: options.success || null,
					username: options.username || null
				};
				if(!JM.pjax.flag){
					//alert(7)
					for(var name in localStorage){
						if(name.split("-")[0] === "PJAX"){
							localStorage.removeItem(name);
						}
					}
					JM.pjax.flag = true;
					JM.event.addEvent(window, "popstate", function(evt){
						var data = localStorage.getItem(evt.state.id);
						options.success(data);
					});
				}
				opts.beforeSend = function(xhr){
					xhr.setRequestHeader("X-PJAX", true);
					if(options.beforeSend){ options.beforeSend(xhr);}
				};
				opts.success = function(response, xhr){
					if(options.success){ options.success(response, xhr);}
					if(JM.pjax.state && JM.pjax.state.title){
						title = JM.pjax.state.title;
					}else{
						if(elem && elem.title){
							title = elem.title;
						}else{
							title = document.title;
						}
					}
					state = {id: id};
					history.pushState(state, title, opts.url);
					document.title = title;
					localStorage.setItem(id, response);
				};
				JM.ajax.make(opts.url, opts);
			}
		}
	};

	//pjax.make()
	//目录树
	var menuTree = JM.menuTree = {
		previousMenu: null,
		previousMenuItem: null,
		fold: function(evt){
			var elem, url;
			if(evt){
				evt = JM.event.getEvent(evt);
				elem = JM.event.getElement(evt);
			}else{
				elem = menuTree.previousMenuItem;
			}
			if(elem.nodeName == "SPAN"){
				elem = elem.parentNode;
				alert(elem.firstChild.href)
				if(elem.nodeName == "LI"){
					if(menuTree.previousMenuItem == elem){ return;}
					if(menuTree.previousMenuItem){
						menuTree.previousMenuItem.className = "jm-subMenuItem";
					}
					menuTree.previousMenuItem = elem;
					elem.className = "jm-subMenuItem-current";
					url = elem.firstChild.href;
					JM.menuTree.handleClick(url);
					return;
				}
			}else if(elem.nodeName == "LI"){
				alert(elem.firstChild.href)
				if(menuTree.previousMenuItem == elem && evt){ return;}
				if(menuTree.previousMenuItem){
					menuTree.previousMenuItem.className = "jm-subMenuItem";
				}
				menuTree.previousMenuItem = elem;
				elem.className = "jm-subMenuItem-current";
				url = elem.firstChild.href;
				JM.menuTree.handleClick(url);
				return;
			}else if(elem.nodeName == "A"){
				JM.event.preventDef(evt);
				url = elem.href;
				alert(elem.firstChild.href)
				elem = elem.parentNode;
				if(elem.nodeName == "LI"){
					if(menuTree.previousMenuItem == elem){ return;}
					if(menuTree.previousMenuItem){
						menuTree.previousMenuItem.className = "jm-subMenuItem";
					}
					menuTree.previousMenuItem = elem;
					elem.className = "jm-subMenuItem-current";
					JM.menuTree.handleClick(url);
					return;
				}
			}
			if(!url){
				url = elem.childNodes[1].href;
			}
			if(menuTree.previousMenu != elem.parentNode){
				menuTree.previousMenu.className = "jm-menuItem";
				menuTree.previousMenu = elem.parentNode;
				menuTree.previousMenu.className = "jm-menuItem-current";
				if(menuTree.previousMenuItem){
					menuTree.previousMenuItem.className = "jm-subMenuItem";
					menuTree.previousMenuItem = null;
				}
				/*menuTree.previousMenuItem = menuTree.previousMenu.children[1].children[0];
				if(menuTree.previousMenuItem){ menuTree.previousMenuItem.className = "jm-subMenuItem-current";}*/
				JM.menuTree.handleClick(url);
				document.getElementById("jm-sidebar").style.height = ((document.body.scrollHeight > document.documentElement.clientHeight)?document.body.scrollHeight:document.documentElement.clientHeight) + "px";
			}
		},
		handleClick: function(url){
			//alert(url)
			var xhr = JM.ajax.createXHR();
			document.getElementById("jm-sidebar").style.height = document.documentElement.clientHeight;
			var index = JM.popup.loading();
			JM.pjax.make("", "", {url: url,
				success: function(data){
					ajax.html(data, document.getElementById("jm-main"));
					document.getElementById("jm-sidebar").style.height = ((document.body.scrollHeight > document.documentElement.clientHeight)?document.body.scrollHeight:document.documentElement.clientHeight) + "px";
					if(document.getElementById("jm-UEditor")){
						UE.delEditor("jm-UEditor");
						var ue = UE.getEditor('jm-UEditor');
					}
					JM.popup.close(index);
				}
			});
		}
	};

	/*分页函数*/
	/********/
	var page = JM.page = {
		name: "JMPage",
		version: ".1",
		author: "麦草CMS",
		pagination: 0,
		listNum: 5,
		pageCount: 0,
		previous: null,
		totalRecords: 0,
		recordsNum: 0,
		baseURL: "",
		pageId: "",
		page: null,
		orderId: "",
		orderOf: "",
		sortId: "",
		sortOf: "",
		recordsNumId: "",
		searchId: "",
		searchString: "",
		content: null,
		init: function(options){
			var options = options || {};
			options = {	
				pagination: options.pagination || 1,
				listNum: options.listNum || 5,
				pageCount: options.pageCount || 0,
				previous: options.previous || null,
				totalRecords: options.totalRecords || 0,
				recordsNum: options.recordsNum || 0,
				baseURL: options.baseURL,// || location.href,
				pageId: options.pageId || "pid",
				page: options.page,
				content: options.content,
				orderOf: options.orderOf,
				orderId: options.orderId || "order",
				sortOf: options.sortOf,
				sortId: options.sortId || "sort",
				recordsNumId: options.recordsNumId || "recordsNum",
				searchId: options.searchId || "search",
				searchString: options.searchString
			};
			this.pagination = options.pagination;
			this.listNum = options.listNum;
			this.pageCount = options.pageCount;
			this.previous = options.previous;
			this.totalRecords = options.totalRecords;
			this.recordsNumId = options.recordsNumId;
			this.recordsNum = options.recordsNum;
			this.baseURL = options.baseURL;
			this.pageId = options.pageId;
			this.page = options.page;
			this.content = options.content;
			this.orderId = options.orderId;
			this.orderOf = options.orderOf;
			this.sortId = options.sortId;
			this.sortOf = options.sortOf;
			this.searchId = options.searchId;
			this.searchString = options.searchString;
			this.make(1);
				  JM.event.addEvent(document.getElementById("jm-checkAll"), "click", JM.page.checkAll);
				  JM.event.addEvent(document.getElementById("jm-table-order"), "change", JM.page.order);
				  JM.event.addEvent(document.getElementById("jm-table-showMany"), "change", JM.page.showMany);
				  JM.event.addEvent(document.getElementById("jm-goSearch"), "click", JM.page.goSearch);
		},
		//万能分页函数
		make: function(pagination1){
			var index = this.baseURL.indexOf("?");
			var s = (index == -1) ? "?" : "&";
			var url = this.baseURL + s + this.pageId + "=" + pagination1;
			var div = this.page.children[0];
			var text = "共" + this.pageCount + "页," + this.totalRecords + "条记录";
			div.children[0].innerHTML = text;
			var html = "";
			var p_ul;
			/*div.className = "jm-pagination";
			html = '<div class="jm-p-outline">' + text + '</div>\r\n';
			html += '<ul><li class="jm-previous">上一页</li><li class="jm-current"><a href="">1</a><li class="jm-next">下一页</li></ul>\r\n';
			html += '<div class="jm-redirect-div">\r\n';
			html += '<form id="jm-redirect-form" action="search.php" method="post">\r\n';
			html += '<input id="jm-pageNumber" type="text">\r\n';
			html += '<button type="submit" id="jm-go">Go</button>\r\n';
			html += '</form>\r\n';
			html += '</div>\r\n';
			html += '<div class="jm-hidden"></div>\r\n';
			div.innerHTML = html;
			p.innerHTML = "";*/
			var p_ul = div.children[1];
			JM.event.addEvent(p_ul, "click", JM.page.ul);
			JM.event.addEvent(document.getElementById("jm-go"), "click", JM.page.go);
			JM.event.addEvent(document.getElementById("jm-pageNumber"), "focus", JM.page.emptyThis);
			if(!pagination1 || (this.pagination == pagination1) || this.pageCount <= 1){ return;}
			if(pagination1 > this.pageCount){ pagination1 = this.pageCount;}
			if(!this.previous){
				this.previous = p_ul.childNodes[1];
			}
			if(this.pageCount <= this.listNum){
				this.previous.className = "";
				this.previous = p_ul.childNodes[pagination1];
				this.previous.className = "jm-current";
				this.pagination = pagination1;
			}else if(this.pageCount > this.listNum){
				var half = Math.round((this.listNum/2));
				var halfToInt = parseInt((this.listNum/2));
				var start = pagination1 - halfToInt;
				var diff = this.pageCount - pagination1;
				var firstLi = p_ul.firstChild.cloneNode(true);
				var lastLi = p_ul.lastChild.cloneNode(true);
				var li = p_ul.childNodes[1];
				li.className = "";
				p_ul.innerHTML = "";
				p_ul.appendChild(firstLi);
				if(diff < half){
					start = this.pageCount - this.listNum + 1;
				}
				if(pagination1 <= half){
					start = 1;
				}
				for(var i = 0; i < this.listNum; i++){
					var newLi = li.cloneNode(true);
					newLi.firstChild.innerHTML = start;
					newLi.firstChild.href = url + start;
					if(pagination1 == start){
						newLi.className = "jm-current";
						this.previous = newLi;
					}
					p_ul.appendChild(newLi);
					start ++;
				}
				//alert(8)
				p_ul.appendChild(lastLi);
				this.pagination = pagination1;
				//if(this.pagination == 1){ p_ul.firstChild.className = "jm-p-disabled";}
				if(this.pagination == this.pageCount){ p_ul.lastChild.className = "jm-p-disabled";}
				JM.ajax.make(url, {success: function(data){
						page.content.innerHTML = data;
						//ajax.html(xhr.responseText, page.content);
						JM.event.addEvent(document.getElementById("jm-checkAll"), "click", page.checkAll);
					}
				});
			}
		},
		ul: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var url = "#";
			if(elem.nodeName == "A"){
				JM.event.preventDef(evt);
				elem = elem.parentNode;
			}else if(elem.nodeName == "UL"){
				return;
			}
			switch(elem.className){
				case "jm-previous":
					var pagination1 = page.pagination - 1;
					JM.page.make(pagination1);
					break;
				case "jm-next":
					var pagination1 = page.pagination + 1;
					if(pagination1 > page.pageCount){ return;}
					JM.page.make(pagination1);
					break;
				default:
					var pagination1 = parseInt(elem.firstChild.innerHTML);
					if(page.pagination == pagination1){ return;}
					JM.page.make(pagination1);
					break;
			}
		},
		go: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var form = elem.form;
			var pagination1 = parseInt(form.elements[0].value);
			JM.event.preventDef(evt);
			JM.page.make(pagination1);
		},
		emptyThis: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			elem.value = "";
		},
		order: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var value = elem.options[elem.selectedIndex].value;
			var href = menuTree.previousMenuItem.children[0].href;
			var index = href.indexOf("?");
			var s = (index == -1) ? "?" : "&";
			var href1;
			page.sortOf = value;
			href1 = href + s + page.orderId + "=" + page.orderOf + "&" + page.recordsNumId + "=" + page.recordsNum;
			if(page.searchString){
				href1 += "&" + page.searchId + "=" + page.searchString;
				href1 += "&" + page.sortId + "=" + page.sortOf;
			}
			JM.menuTree.previousMenuItem.children[0].href = href1;
			JM.menuTree.fold();
			JM.menuTree.previousMenuItem.children[0].href = href;
		},
		showMany: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var value = elem.options[elem.selectedIndex].value;
			var href = menuTree.previousMenuItem.children[0].href;
			var index = href.indexOf("?");
			var s = (index == -1) ? "?" : "&";
			var href1;
			page.recordsNum = value;
			href1 = href + s + page.orderId + "=" + page.orderOf + "&" + page.recordsNumId + "=" + page.recordsNum;
			if(page.searchString){
				href1 += "&" + page.searchId + "=" + page.searchString;
				href1 += "&" + page.sortId + "=" + page.sortOf;
			}
			JM.menuTree.previousMenuItem.children[0].href = href1;
			JM.menuTree.fold();
			JM.menuTree.previousMenuItem.children[0].href = href;
		},
		goSearch: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var value = document.getElementById("jm-search-keywords").value;
			var href = menuTree.previousMenuItem.children[0].href;
			var index = href.indexOf("?");
			var s = (index == -1) ? "?" : "&";
			var href1;
			JM.event.preventDef(evt);
			if(value){
				page.searchString = value;
				page.sortOf = document.getElementById("jm-table-sort").value;
				href1 = href + s + page.orderId + "=" + page.orderOf + "&" + page.recordsNumId + "=" + page.recordsNum;
				href1 += "&" + page.searchId + "=" + page.searchString;
				href1 += "&" + page.sortId + "=" + page.sortOf;
				JM.menuTree.previousMenuItem.children[0].href = href1;
				JM.menuTree.fold();
				JM.menuTree.previousMenuItem.children[0].href = href;
			}
		},
		checkAll: function(evt){
			var evt = JM.event.getEvent(evt);
			var elem = JM.event.getElement(evt);
			var form = elem.form;
			for(var i in form.elements){
				if(elem.checked){
					if(form.elements[i].type == "checkbox"){ form.elements[i].checked = "true";}
				}else{
					if(form.elements[i].type == "checkbox"){ form.elements[i].checked = "";}
				}
			}
		}
	};
	/*分页函数*/

	//弹窗
	var popup = JM.popup = {
		name: "JMPopup",
		version: ".1",
		author: "麦草CMS",
		defaultTitle: "麦草CMS这样说：",
		index: 0,
		counter: 0,
		parentIndex: null,
		isShade: false,
		parentIndexs: [],
		pointer: 0,
		indexs: [],//这里可以缓存整个弹窗元素，但目前缓存了元素ID。
		indexCache: [],
		shadeIndexs: [],
		shadeIndexCache: [],	
		isNew: false,
		//timeItems: [],
		//timeItemCache: [],
		timers: [],
		outerClickIndexs: [],
		outerClickIndexs1: [],
		//timerCache: [],
		tipTargets: [],
		X: false,
		Y: false,
		bool: false,
		set: function(name, value){
			this[name] = value;
		},
		make: function(type, content, defaultValue, options, target){
			var options = options || {};
			options = {
				shade: "undefined" == typeof options.shade ? false : options.shade,
				title: "undefined" == typeof options.title ? JM.popup.defaultTitle : options.title,
				width: options.width,
				height: options.height,
				closeBtn: "undefined" == typeof options.closeBtn ? true : options.closeBtn,
				resizeBtn: options.resizeBtn,
				time: parseFloat("undefined" == typeof options.time ? 0 : options.time),
				yes: type == "jm-alert" ? null : options.yes,
				no: type == "jm-alert" ? null : options.no,
				position: options.position,
				top: options.top,
				right: options.right,
				bottom: options.bottom,
				left: options.left,
				style: options.style,
				buttons: options.buttons || ["确定", "取消"],
				outerClick: "undefined" == typeof options.outerClick ? true : options.outerClick,
				animation: options.animation || "",
				direction: options.direction || /*"vertical",//*/"horizontal",
				tipStyle: options.tipStyle || "zhi",
				tipPosition: options.tipPosition || /*"follow"//*/"target"
			};
			var index, popupId, parent, div, div1, div2, d1, d2, d3, xmp, xmp1, label, textarea, iframe, span, span1, btn1, btn2, height, evt, elem = null;
			if(type == "tips"){
				evt = JM.event.getEvent(target);
				elem = evt ? JM.event.getElement(evt) : target;
				for(var i = 0, arr = JM.popup.tipTargets;i < arr.length; i++){
					if(arr[i] === elem){
						if(evt){
							JM.event.cancelBubble(evt);
						}
						return;
					}
				}
			}
			//this.outerClickPopupsClose();
			//alert(this.tipTargets)
			//alert(this.indexs)
			this.index++;
			popupId = "_popup_" + this.index;
			function divMake(){
	  			//div = document.createElement("div");
				//div.className = "jm-popup";
				d1 = document.createElement("div");
				//form = document.createElement("form");
				d1.className = "jm-popupTitle";
				xmp1 = document.createElement("xmp");
				span = document.createElement("span");
				span.className = "jm-resize";
				span.innerHTML = "&#xf00b3;";
				span1 = document.createElement("span");
				span1.className = "jm-close";
				span1.innerHTML = "&#xf00b3;";
				d1.appendChild(xmp1);
				d1.appendChild(span);
				d1.appendChild(span1);
				div.appendChild(d1);
				div.appendChild(d2);
	  			d3 = document.createElement("div");
				d3.className = "jm-popupButtons clearfix";
	  			btn1 = document.createElement("button");
				btn1.setAttribute("type", "button");
				btn1.id = "jm-submit";
				d3.appendChild(btn1);
	  			btn2 = document.createElement("button");
				btn2.setAttribute("type", "button");
				btn2.id = "jm-cancel";
				d3.appendChild(btn2);
				div.appendChild(d3);
				//div.appendChild(form);
				//div.appendChild(div);
				if(!options.closeBtn){ span1.style.display = "none";}
				if(options.resizeBtn){ span.style.display = "inline-block";}
				if(options.buttons && "undefined" == typeof options.buttons[0]){
					options.buttons[0] = options.buttons;
					options.buttons[1] = "";
				}
				if(options.buttons[0]){
					btn1.innerHTML = options.buttons[0];
				}else{
					btn1.style.display = "none";
				}
				if(options.buttons[1]){
					btn2.innerHTML = options.buttons[1];
				}else{
				btn2.style.display = "none";
				}
				//alert(xmp1+options.title)
				var s = document.createTextNode(options.title);
				xmp1.appendChild(s);
				//xmp1.innerHTML = options.title;
				//index = JM.popup.index;
				JM.event.addEvent(span1, "click", function(){ JM.popup.close(div2);});
				JM.event.addEvent(btn2, "click", function(){ JM.popup.cancel(div2, options.no, popupId, textarea);});
				JM.event.addEvent(btn1, "click", function(){ JM.popup.submit(div2, options.yes, popupId, textarea);});
				//JM.event.addEvent(span, "click", JM.popup.resize);
				//return div;
			}
			function restructureTail(direction){
				switch(options.tipStyle){
					case "zhi":
						switch(direction){
							case "bottom":
								d1.children[0].style.top = "auto";
								d1.children[0].style.bottom = "10px";
								break;
							case "right":
								d1.children[0].style.left = "auto";
								d1.children[0].style.right = "10px";
								break;
						}
						break;
					case "jian":
						switch(direction){
							case "bottom":
								d1.children[0].style.top = "auto";
								d1.children[0].style.bottom = "10px";
								break;
							case "right":
								d1.children[0].style.left = "auto";
								d1.children[0].style.right = "10px";
								break;
						}
						break;
					case "dun":
						switch(direction){
							case "bottom":
								d1.children[0].style.top = "auto";
								d1.children[0].style.bottom = "10px";
								d1.children[1].style.top = "auto";
								d1.children[1].style.bottom = "10px";
								break;
							case "right":
								d1.children[0].style.left = "auto";
								d1.children[0].style.right = "10px";
								d1.children[1].style.left = "auto";
								d1.children[1].style.right = "10px";
								break;
						}
						break;
				}
			}
			function tipsFunc(){
				if(relPos.y < 30){
									//alert(5)
									//h = absPos.y - evt.offsetY + elem.offsetHeight;
					if(absPos.y < 30){
										//diff = scroll.height - absPos.y;
						scrollTo(absPos.x - relPos.x, 0);
							absPos.y = 30;
							relPos.y = 30;
					}else{
						diff = 30 - relPos.y;
						scrollTo(absPos.x - relPos.x, absPos.y - diff);
						relPos.y = 30;
					}
				}
				if(relPos.y > client.height - 30){
					//alert(4)
					//h = scroll.height - absPos.y;
					diff = 30 - client.height - relPos.y;
					if(scroll.height - absPos.y < 30){
						scrollTo(absPos.x - relPos.x, scroll.height - client.height);
						absPos.y = scroll.height - 30;
						relPos.y = client.height - 30;
					}else{
						scrollTo(absPos.x - relPos.x, absPos.y + diff);
						relPos.y = client.height - 30;
					}
				}
				if(relPos.x < 30){
									//alert(5)
									//h = absPos.y - evt.offsetY + elem.offsetHeight;
					if(absPos.x < 30){
										//diff = scroll.height - absPos.y;
						scrollTo(0, absPos.y - relPos.y);
						absPos.x = 30;
						relPos.x = 30;
					}else{
						diff = 30 - relPos.x;
						scrollTo(absPos.x - diff, absPos.y - relPos.y);
						relPos.x = 30;
					}
				}
				if(relPos.x > client.width - 30){
									//alert(4)
									//h = scroll.height - absPos.y;
					diff = 30 - client.width - relPos.x;
					if(scroll.width - absPos.x < 30){
						scrollTo(scroll.width - client.width, absPos.y - relPos.y);
						absPos.x = scroll.width - 30;
						relPos.x = client.width - 30;
					}else{
						scrollTo(absPos.x + diff, absPos.y - relPos.y);
						relPos.x = client.width - 30;
					}
				}
				tipsLeft = ((relPos.x + (elem.offsetWidth/2)) < client.width/2) ? true : false;
				tipsTop = ((relPos.y + (elem.offsetHeight/2)) < client.height/2) ? true : false;
			}
	  		div = document.createElement("div");
			div.className = "jm-popup " + options.animation;
			//alert(4)
			if(options.shade){
				parent = document.createElement("div");
				parent.className = "jm-popupContainer";
				parent = document.body.appendChild(parent);
				div1 = document.createElement("div");
				div1.className = "jm-shade";
				parent.appendChild(div1);
				div2 = parent;
				if(!this.isShade) { this.pointer = popupId;}
				if(this.parentIndex && this.isShade){
					for(var i = 0, popups = this.indexs; i < popups.length; i++){
						if(popups[i] == this.parentIndex){ break;}
					}
					this.isNew = true;
					this.indexs.splice(i, 0, popupId);
					this.indexCache.splice(i, 0, 1);
					this.parentIndexs.splice(i, 0, this.parentIndex);
					this.tipTargets.splice(i, 0, elem);
					this.shadeIndexs.unshift(popupId);
					this.pointer = popupId;
					//this.parentIndex = null;
				}else{
					if(this.index - 1 && this.isShade){
						div2.style.visibility = "hidden";
					}
					this.indexs.push(popupId);
					this.indexCache.push(1);
					this.parentIndexs.push(0);
					this.tipTargets.push(elem);
					this.shadeIndexs.push(popupId);
				}
			}else{
				parent = document.body;
				div2 = div;
				if(this.parentIndex && this.isShade){
					for(var i = 0, popups = this.indexs; i < popups.length; i++){
						if(popups[i] == this.parentIndex){ break;}
					}
					this.isNew = true;
					this.indexs.splice(i, 0, popupId);
					this.indexCache.splice(i, 0, 0);
					this.parentIndexs.splice(i, 0, this.parentIndex);
					this.tipTargets.splice(i, 0, elem);
					//this.parentIndex = null;
				}else{
					if(this.index - 1 && this.isShade){
						div2.style.visibility = "hidden";
					}
					this.indexs.push(popupId);
					this.indexCache.push(0);
					this.parentIndexs.push(0);
					this.tipTargets.push(elem);
				}
			}
			//alert(5)
			parent.appendChild(div);
			div2.id = popupId;
			switch(type){
				case "jm-normal":
	  				d2 = document.createElement("div");
					d2.className = "jm-popupContent";
					label = document.createElement("label");
					label.innerHTML = content;
					d2.appendChild(label);
					divMake();
					if("undefined" != typeof options.width){ div.style.width = options.width;}
					if("undefined" != typeof options.height){
						div.style.height = options.height;
						d2.style.height = (div.offsetHeight - d1.offsetHeight -  d3.offsetHeight) + "px";
					}else{
						height = (d2.offsetHeight +  d1.offsetHeight +  d3.offsetHeight) + "px";
						div.style.height = height;
					}
					break;
				case "jm-alert":
					options.outerClick = false;
	  				d2 = document.createElement("div");
					d2.className = "jm-popupContent";
					xmp = document.createElement("xmp");
					xmp.innerHTML = content;
					d2.appendChild(xmp);
					divMake();
					btn2.className = "hidden";
					if("undefined" != typeof options.width){ div.style.width = options.width;}
					if("undefined" != typeof options.height){
						div.style.height = options.height;
						d2.style.height = (div.offsetHeight - d1.offsetHeight -  d3.offsetHeight) + "px";
					}else{
						height = (d2.offsetHeight +  d1.offsetHeight +  d3.offsetHeight) + "px";
						div.style.height = height;
					}
					break;
				case "jm-confirm":
					options.outerClick = false;
	  				d2 = document.createElement("div");
					d2.className = "jm-popupContent";
					xmp = document.createElement("xmp");
					xmp.innerHTML = content;
					d2.appendChild(xmp);
					divMake();
					if("undefined" != typeof options.width){ div.style.width = options.width;}
					if("undefined" != typeof options.height){
						div.style.height = options.height;
						d2.style.height = (div.offsetHeight - d1.offsetHeight -  d3.offsetHeight) + "px";
					}else{
						height = (d2.offsetHeight +  d1.offsetHeight +  d3.offsetHeight) + "px";
						div.style.height = height;
					}
					break;
				case "jm-prompt":
					options.outerClick = false;
	  				d2 = document.createElement("div");
					d2.className = "jm-popupContent";
					xmp = document.createElement("xmp");
					xmp.innerHTML = content;
					textarea = document.createElement("textarea");
					textarea.innerHTML = defaultValue;
					d2.appendChild(xmp);
					d2.appendChild(textarea);
					divMake();
					if("undefined" != typeof options.width){ div.style.width = options.width;}
					if("undefined" != typeof options.height){
						div.style.height = options.height;
						d2.style.height = (div.offsetHeight - d1.offsetHeight -  d3.offsetHeight) + "px";
					}else{
						height = (d2.offsetHeight +  d1.offsetHeight +  d3.offsetHeight) + "px";
						div.style.height = height;
					}
					break;
				case "iframe":
					//alert(type)
	  				d2 = document.createElement("div");
					d2.className = "jm-popupContent";
					label = document.createElement("xmp");
					iframe = document.createElement("iframe");
					iframe.src = content;
					label.appendChild(iframe);
					d2.appendChild(label);
					divMake();
					if("undefined" != typeof options.width){
						div.style.width = options.width;
						iframe.style.width = (div.offsetWidth - 10) + "px";
					}else{
						options.width = (label.offsetWidth + 10) + "px";
					}
					if("undefined" != typeof options.height){
						div.style.height = options.height;
						iframe.style.height = (div.offsetHeight - d1.offsetHeight -  d3.offsetHeight - 10) + "px";
					}
					break;
				case "dynamic":
					d1 = document.createElement("div");
					d1.className = "jm-loading";
					d1.innerHTML = content;
					div.appendChild(d1);
					//alert(d1.offsetWidth)
					if("undefined" == typeof options.width){
						div.style.width = d1.offsetWidth + "px";
					}else{
						div.style.width = options.width;
					}
					if("undefined" == typeof options.height){
						div.style.height = d1.offsetHeight + "px";
					}else{
						div.style.height = options.height;
					}
					break;
				case "loading":
					options.outerClick = false;
					div.className = "jm-popup2 " + options.animation;
					d1 = document.createElement("div");
					d1.className = "jm-dynamic fa fa-5x fa-spinner fa-pulse";
					//d1.innerHTML = content;
					div.appendChild(d1);
					//alert(d1.offsetWidth)
					div.style.width = d1.offsetWidth + "px";
					div.style.height = d1.offsetHeight + "px";
					break;
				case "tips":
					var absPos = JM.utils.getAbs(elem),
						relPos = JM.utils.getRel(elem),
						client = JM.utils.getViewport(),
						scroll = JM.utils.getPagearea(),
						diff, tipsLeft, tipsTop;
				//alert(absPos.y)
					options.position = "absolute";
			        this.bool = true;
					div.className = "jm-popup1" + options.animation;
					d1 = document.createElement("div");
					d1.className = "tip ";
					div.appendChild(d1);
					span = document.createElement("span");
					span.className = "tail-bottom";
					span1 = document.createElement("span");
					span1.className = "tail-top";
					d1.appendChild(span);
					d1.appendChild(span1);
					d1.innerHTML += content;
					if("undefined" != typeof options.width){ div.style.width = options.width;}
					if("undefined" != typeof options.height){ div.style.height = options.height;}
					//alert(6)
					//if(!options.direction){ options.direction = "horizontal";}
					if(evt && options.tipPosition == "follow"){
						//alert(1)
						switch(options.direction){
							case "horizontal":
								tipsFunc();
								if(tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-right";
									options.top = (absPos.y + evt.offsetY - 34) + "px";
									options.left = absPos.x + evt.offsetX + "px";
								}
								if(!tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-left";
									options.top = (absPos.y + evt.offsetY - 34) + "px";
									options.left = (absPos.x + evt.offsetX - div.offsetWidth) + "px";
								}
								if(tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-right";
									options.top = (absPos.y + evt.offsetY - div.offsetHeight + 34) + "px";
									options.left = absPos.x + evt.offsetX + "px";
									restructureTail("bottom");
								}
								if(!tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-left";
									options.top = (absPos.y + evt.offsetY - div.offsetHeight + 34) + "px";
									options.left = (absPos.x + evt.offsetX - div.offsetWidth) + "px";
									restructureTail("bottom");
								}
								break;
							case "vertical":
								tipsFunc();
								if(tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-bottom";
									options.left = (absPos.x + evt.offsetX - 34) + "px";
									options.top = absPos.y + evt.offsetY + "px";
								}
								if(!tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-bottom";
									options.left = (absPos.x + evt.offsetX - div.offsetWidth + 34) + "px";
									options.top = absPos.y + evt.offsetY + "px";
									restructureTail("right");
								}
								if(tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-top";
									options.left = (absPos.x + evt.offsetX - 34) + "px";
									options.top = (absPos.y + evt.offsetY - div.offsetHeight) + "px";
								}
								if(!tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-top";
									options.left = (absPos.x + evt.offsetX - div.offsetWidth + 34) + "px";
									options.top = (absPos.y + evt.offsetY - div.offsetHeight) + "px";
									restructureTail("right");
								}
								break;
						}
					}else{
						switch(options.direction){
							case "horizontal":
								tipsFunc();
								if(tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-right";
									options.top = (absPos.y - 20) + "px";
									options.left = absPos.x + elem.offsetWidth + "px";
								}
								if(!tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-left";
									options.top = (absPos.y - 20) + "px";
									options.left = (absPos.x - div.offsetWidth) + "px";
								}
								if(tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-right";
									options.top = (absPos.y - div.offsetHeight + elem.offsetHeight) + "px";
									options.left = absPos.x + elem.offsetWidth + "px";
									restructureTail("bottom");
								}
								if(!tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-left";
									options.top = (absPos.y - div.offsetHeight + elem.offsetHeight) + "px";
									options.left = (absPos.x - div.offsetWidth) + "px";
									restructureTail("bottom");
								}
								break;
							case "vertical":
								tipsFunc();
								if(tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-bottom";
									options.left = absPos.x + "px";
									options.top = absPos.y + elem.offsetHeight + "px";
								}
								if(!tipsLeft && tipsTop){
									d1.className += "tip-" + options.tipStyle + "-bottom";
									options.left = (absPos.x - div.offsetWidth + elem.offsetWidth) + "px";
									options.top = absPos.y + elem.offsetHeight + "px";
									restructureTail("right");
								}
								if(tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-top";
									options.left = absPos.x + "px";
									options.top = (absPos.y - div.offsetHeight) + "px";
								}
								if(!tipsLeft && !tipsTop){
									d1.className += "tip-" + options.tipStyle + "-top";
									options.left = (absPos.x - div.offsetWidth  + elem.offsetWidth) + "px";
									options.top = (absPos.y - div.offsetHeight) + "px";
									restructureTail("right");
								}
								break;
						}
					}/*else{
					}*/
					//JM.popup.tipTargets.push(elem);
					//options.width = div.offsetWidth;
					//options.height = div.offsetHeight;
					break;
			}
			if(options.outerClick){
				this.outerClickIndexs.push(popupId);
				if(this.parentIndex){
					this.outerClickIndexs1.push(popupId);
				}
			}
			if("undefined" != typeof options.position){
				div.style.position = options.position;
			}
			if("undefined" != typeof options.top){
				//alert(options.top)
				div.style.top = options.top;
				div.style.bottom = "auto";
				this.Y = true;
			}
			if("undefined" != typeof options.right){
				div.style.right = options.right;
				div.style.left = "auto";
				this.X = true;
			}
			if("undefined" != typeof options.bottom){
				div.style.bottom = options.bottom;
				if(!this.Y){
					div.style.top = "auto";
				}
			}
			if("undefined" != typeof options.left){
				div.style.left = options.left;
				if(!this.X){
					div.style.right = "auto";
				}
			}
			this.X = false;
			this.Y = false;
			//alert(div2.outerHTML)
			//alert(this.timers)
			JM.event.addEvent(div, "click", function(evt){
				JM.event.cancelBubble(evt);
			});
			if(this.index == 1){ JM.event.addEvent(document.body, "click", JM.popup.outerClickPopupsClose);}
			this.setTimer(div2, options.shade, options.time, i);
			return div2;
		},
		close: function(div){
			var timer, index = 0, div1, flag = null, flag1 = 0, bool = false;
			//alert(this.timers)
			//alert(div.id)
			for(var i = 0, popups = this.indexs; i < popups.length; i++){
				if(div.id == popups[i]){ break;}
			}
			if(this.shadeIndexs.length && this.indexCache[i]){
				if(this.isNew){
					//alert(this.indexs[i])
					//alert(this.indexCache[i])
					if(this.indexCache[i]){
						/*for(var k = 0; k < this.shadeIndexs.length; k++){
						}*/
							//alert(9)
						if(this.indexCache[i-1]){
							index = 1;
							//alert(8)
						}
					}
					//alert(i)
					//i++;
					this.shadeIndexs.splice(index, 1);
					if(this.shadeIndexs.length){
						for(var j = 0; j < this.shadeIndexs.length; j++){
							if(this.shadeIndexs[j] == this.pointer){ bool = true; break;}
						}
						if(!bool){
							for(var j = 0; j < this.indexs.length; j++){
								if(this.indexs[j] == this.shadeIndexs[0]){
									div1 = document.getElementById(this.indexs[j]);
									div1.style.visibility = "visible";
									timer = this.timers[j] ? setTimeout( function(){ JM.popup.close(div1);}, JM.popup.timers[j] * 1000) : -1;
									this.timers.splice(j, 1, timer);
									break;
								}
							}
						}
					}
					//alert(this.shadeIndexs)
				}else{
					for(var z = 0; z < this.shadeIndexs.length; z++){
						//alert(div.id)
						if(this.shadeIndexs[z] == div.id){ flag = z; continue}
						if(this.parentIndex && this.parentIndex == this.shadeIndexs[z]){ flag1 = z; continue;}
					}
						//alert(this.shadeIndexs)
					//alert(flag + ""+ flag1)
					if(flag <= flag1){
						for(var j = 0, popups = this.indexs; j < popups.length; j++){
							if(this.shadeIndexs[1] == popups[j] || !this.shadeIndexs[1]){
								for(var k = i+1; k < this.indexs.length; k++){
									div1 = document.getElementById(this.indexs[k]);
									div1.style.visibility = "visible";
									timer = this.timers[k] ? setTimeout( function(){ JM.popup.close(div1);}, JM.popup.timers[k] * 1000) : -1;
									this.timers.splice(k, 1, timer);
									//alert(JM.popup.indexs[k])
									if(this.indexs[k] == this.indexs[j]){ break;}
								}
								break;
							}
						}
					}
					this.shadeIndexs.splice(flag, 1);
				}
				this.pointer = this.shadeIndexs[0];
			}
			if(this.shadeIndexs.length == 0){
				this.isShade = false;
			}
			clearTimeout(JM.popup.timers[i]);
			document.body.removeChild(div);
			JM.popup.indexs.splice(i, 1);
			JM.popup.indexCache.splice(i, 1);
			JM.popup.parentIndexs.splice(i, 1);
			JM.popup.timers.splice(i, 1);
			JM.popup.tipTargets.splice(i, 1);
			for(var i = 0, arr = this.outerClickIndexs; i < arr.length; i++){
				if(arr[i] == div.id){
					JM.popup.outerClickIndexs.splice(i, 1);
					break;
				}
			}
			for(var i = 0, arr = this.outerClickIndexs1; i < arr.length; i++){
				if(arr[i] == div.id){
					JM.popup.outerClickIndexs1.splice(i, 1);
					break;
				}
			}
			//alert(this.indexs)
			//alert(this.timers)
			this.isNew = false;
			if(JM.popup.indexs.length  == 0){
				JM.popup.index = 0;
				JM.popup.pointer = 0;
			}
			//alert(this.indexs)
				//alert(this.indexCache)
		},
		outerClickPopupsClose: function(){
			//alert(JM.popup.outerClickIndexs)
			//alert(JM.popup.pointer)
			var index,
				arr,
				flag = null;
			//alert(1)
			if(JM.popup.shadeIndexs.length){
				//alert(JM.popup.outerClickIndexs1)
				//alert(JM.popup.shadeIndexs[0])
				while(JM.popup.outerClickIndexs1.length){
					index = JM.popup.outerClickIndexs1.pop();
					JM.popup.close(document.getElementById(index));
				}
				for(var i = 0, arr1 = JM.popup.outerClickIndexs; i < arr1.length; i++){
					//alert(JM.popup.pointer)
					if(arr1[i] == JM.popup.pointer){
						//alert(index1)
						//alert(JM.popup.indexs[index1])
						//alert(arr1[i])
						//alert(JM.popup.outerClickIndexs)
						JM.popup.close(document.getElementById(arr1[i]));
						//JM.popup.outerClickIndexs.splice(i, 1);
						//alert(JM.popup.outerClickIndexs)
						//alert(2)
						break;
					}
				}
				//return;
			}else{
			//alert(2)
			while(JM.popup.outerClickIndexs.length){
				//alert(3)
				index = JM.popup.outerClickIndexs.shift();
				arr = index.split("_");
				//alert(index)
				if(JM.popup.bool && arr[2] == JM.popup.index){
					flag = index;
					continue;
				}
				//alert(index)
				JM.popup.close(document.getElementById(index));
			}}
			//alert(flag)
			if(flag){
				JM.popup.outerClickIndexs.push(flag);
			}
			if(JM.popup.index == 0){ JM.event.removeEvent(document.body, "click", JM.popup.outerClickPopupsClose);}
			JM.popup.bool = false;
			//alert(JM.popup.indexs)
			//alert(JM.popup.shadeIndexs)
		},
		submit: function(div, yes, index, input){
			var data = input ? input.value : true;
			JM.popup.parentIndex = index;
			if(yes){ yes(data);}
			JM.popup.close(div);
			JM.popup.parentIndex = null;
		},
		cancel: function(div, no, index, input){
			var data = input ? input.value : false;
			JM.popup.parentIndex = index;
			if(no){ no(data);}
			JM.popup.close(div);
			JM.popup.parentIndex = null;
		},
		setTimer: function(div, shade, time, index){
			var timer;
			//alert(div)
			if(shade){
				if(this.parentIndex && this.isShade){
						timer = time  ? setTimeout(function(){ JM.popup.close(div);}, time * 1000) : -1;
					this.timers.splice(index, 0, timer);
				}else{
					if(this.index - 1 && this.isShade){
						timer = time;
					}else{
						//alert(idiv)
						timer = time  ? setTimeout(function(){ JM.popup.close(div);}, time * 1000) : -1;
						//timer = setTimeout(function(){ JM.popup.close(div);}, time * 1000);
					}
					this.timers.push(timer);
				}
				this.isShade = true;
			}else{
				//alert(1)
				if(this.parentIndex && this.isShade){
						timer = time  ? setTimeout(function(){ JM.popup.close(div);}, time * 1000) : -1;
					this.timers.splice(index, 0, timer);
				}else{
					if(this.index - 1 && this.isShade){
						timer = time;
					}else{
						timer = time  ? setTimeout(function(){ JM.popup.close(div);}, time * 1000) : -1;
						//timer = setTimeout(function(){ JM.popup.close(div);}, time * 1000);
					}
					this.timers.push(timer);
					//alert(this.timers)
				}
			}
		},
		alert: function(content, options){
			var options = options || {};
			options.shade = true;
			this.make("jm-alert", content, "", options);
		},
		prompt: function(content, defaultValue, options){
			var options = options || {};
			options.shade = true;
			this.make("jm-prompt", content, defaultValue, options);
		},
		confirm: function(content, options){
			var options = options || {};
			options.shade = true;
			this.make("jm-confirm", content, "", options);
		},
		open: function(content, options){
			this.make("jm-normal", content, "", options);
		},
		iframe: function(content, options){
			this.make("iframe", content, "", options);
		},
		loading: function(content, options){
			return this.make("loading", content, "", options);
		},
		tips: function(content, target, options){
			this.make("tips", content, "", options, target);
		}
	};

JM.popup.open("自定义弹窗8", {top:0, left:1, yes: function(){ popup.alert("");}});
var ss = JM.popup.loading("<i>自定义弹窗</i>");
JM.popup.set("defaultTitle", "<u>测试");//定义它的目的，暂时只为设置默认标题defaultTitle。由于未做限制(个人认为没有必要限制，除非你为了好玩去设置其它的项)，此方法可以改写JM.popup所有属性和方法。
//JM.popup.iframe("blank.html", {width: "600px", height: "100%"});
JM.popup.alert("你满意这样的UI设计吗？这仅仅是一段提示，不会产生任何后台操作，请关闭对话框即可！嘿嘿嘿！哈哈哈！嘻嘻嘻嘻！哼哼哼！", {width: "260px", time: 5.8, top: 0, left: 0, yes: function(){ JM.popup.alert("测试");}/*, bottom: "auto", right: "auto"*/});
JM.popup.prompt("你满意这样的UI设计吗？请你说说看法并做出选择！嘿嘿嘿！哈哈哈！嘻嘻嘻嘻！哼哼哼！", "满意！", {
	shade: false,//值为true或false，是否添加遮罩(某些大咖的对话框UI里定义为锁定，嘿嘿)，配合yes(),no()回调函数模拟JS阻塞。alert,prompt,confirm三个方法始终有遮罩，不可通过次参数更改。
	title: "",//弹窗的标题，不定义此项则默认标题(默认标题通过set(name, value)方法设置)生效。传入空字符串""则表示隐藏标题。
	time: 5.8,//是否定时关闭，为0时即为不定时，单位是秒，可接受形如 0.8, .8, 5.8, 8的数值。方法自动做了处理，值如果是字符串，则"8F"是值8，".8F"是0.8，"F8"是0，true是1等等，但字符串必须带引号。
	width: "350px",//弹窗宽度，带单位的字符串，如"23%"          /*****下面几项是设置CSS样式的，名值对对应CSS同名的样式*******/
	height: "450px",//弹窗高度，带单位的字符串，如"180px"       /********接受CSS样式值，请记住除0外都是带单位的字符串*******/
	top: "50px",//弹窗距顶部距离，带单位的字符串，如"23%"       ****        *这几项设置弹窗的位置      **** 默认相对窗口水平垂直居中，下面例子按top,right,bottom,left顺序，其中值为auto的项和方向相对的值都是0的项请忽略设置，这里仅为书写方便以及便于理解
	//right: "50px",//弹窗距右边距离，带单位的字符串，如"23%"     ****        *                      **** 左上: 0 auto auto 0  右上：0 0 auto auto         **方向相对的两项值相同即该方向上居中
	//bottom: "auto",//弹窗距顶底部距离，带单位的字符串，如"auto"  ****        *一般方向相对的两边不用同时设置 **** 左下：auto auto 0 0  右下：auto 0 0 auto         **具体请参照CSS中同名的属性设置，
	//left: "auto",//弹窗距左边距离，带单位的字符串，如"23%"       ****        *                      **** 上中：0 0 auto 0     下中：auto 0 0 0            **四个值默认为0。设置某项(即使其值是0)，相对的另一项值自动转为auto。
	position: "absolute",//弹窗的定位方式，默认是"fixed",值可为"relative","absolute","fixed"等
	style: "",//样式表引用，可在单独的样式表中做详细设置，在这里引入
	no: function(){ popup.alert("");},//点击否定按钮时的回调函数       /*****prompt的输入值通过data参数传递，为应对某些需求，两个回调函数均传递prompt输入值为data，即no回调函数也能接收输入框的值*****/
	yes: function(data){ popup.alert(data);}//点击否定按钮时的回调函数 /***********对其它弹窗类型没做回调函数限制，故均可设置回调函数，其data参数值分别是true和false,具体做什么，你自己斟酌**********/
});
JM.popup.open("自定义弹窗", {width: "390px", height: "500px", shade: true});
JM.popup.confirm("你满意这样的UI设计吗？请做出你的选择！嘿嘿嘿！哈哈哈！嘻嘻嘻嘻！哼哼哼！", {buttons: ["", ""]});
JM.popup.open("自定义弹窗1");
//弹窗模块的逻辑基本上和JS自带的对话框相同；遮罩即是假阻塞，模拟JS的阻塞。原本的返回值监听函数分别由yes和no回调函数担任，所以除了这一点，弹窗模块的用法和JS的对话框完全一样。理解了前面的一段话，你可以欢欢喜喜的用弹窗了。它们的参数传递也和JS对话框的一致；唯一的区别是它们多了一个options参数(弹窗配置)，options是一个对象字面量，此参数多数是一些CSS样式设置，和弹窗的呈现相关。至于你用JM.popup的alert、confirm、prompt(传入这三个方法的任何字符都将呈现出来，如<html></html><script src="yy.js"></script>将显示为<html></html><script src="yy.js"></script>)三个方法之外的其它JM.popup方法弄进弹窗的dom元素的，与弹窗的监听用户动作的回调函数无关的一些DOM操作，弹窗模块无权干涉；请尽量将它们放在回调函数的外面，最好也是放在JM.popup之外。调用方法：JM.popup.alert("你懂了吗", {title: "麦草CMS这样说：", width: "300px", .....})，JM.popup.prompt("你喜欢弹窗模块吗？", "嗯嗯，非常喜欢！", {title: "麦草CMS这样说：", width: "300px", .....})
JM.popup.close(ss);

function init(){
		var asideMenu = document.getElementById("jm-sidebar-menu");
		document.getElementById("jm-sidebar").style.height = ((document.body.scrollHeight > document.documentElement.clientHeight)?document.body.scrollHeight:document.documentElement.clientHeight) + "px";
		for(var i in asideMenu.childNodes){
			//alert(asideMenu.innerHTML)
			if(asideMenu.childNodes[i].nodeName == "NAV"){ break;}
		}
		asideMenu.childNodes[i].className = "jm-menuItem-current";
		JM.menuTree.previousMenu = asideMenu.childNodes[i];
	JM.event.addEvent(asideMenu, "click", function(evt){
		JM.menuTree.fold(evt);
	});
/*JM.event.addEvent(document.getElementById("jm-shade"), "touchmove", function(evt){
	JM.event.preventDef(evt)
});*/
}
JM.event.addEvent(window, "load", init);
}();
function openPopup(evt){
	var m = 0, n = 800, x, y;
	x = n - m;
	y = parseInt((Math.random() * x) + m, 10);
	y = y + "px";
	JM.popup.tips("<u>" + y + "测试测试测试测试</u>", evt, {shade: false, bottom: y, left: y, tipStyle: "jian"});
}
var ss = JM.popup.loading("<i>自定义弹窗</i>");
JM.popup.open("自定义弹窗6",{top:0});
function closeQQ(){
	JM.popup.close(ss);
}
function c(){
	var evt = JM.event.getEvent("a");
	if(evt)alert(evt)
	//alert(evt)
}
//c()
